package org.example.traing.service.Impl;

import org.example.traing.entity.JobDetail;
import org.example.traing.entity.User;
import org.example.traing.entity.UserDetail;
import org.example.traing.persistence.UserMapper;
import org.example.traing.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("UserService")
public class UserImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User Login(User user) {

        return userMapper.getUser(user);

    }


    @Transactional
    public int addUser(User user){

        int a=userMapper.addUser(user);
        int b=userMapper.addUserDetail(user.getUid());
        if(a==1&&b==1)
        {
            return 1;
        }else {
            return 0;
        }

    }

    public int updateUser(User user){
        return userMapper.updateUser(user);
    }

    public int deleteUser(String uid){
        return userMapper.deleteUser(uid);
    }

    public UserDetail getUserDetail(String uid){

        return userMapper.getUserDetail(uid);


    }


    @Transactional
    public UserDetail  updateUserDetail(UserDetail userDetail){

        userMapper.updateUserDetail(userDetail);
        return userMapper.getUserDetail(userDetail.getUid());

    }

    public List<JobDetail> getTreasureJob(String uid){
        return userMapper.getTreasureJob(uid);

    }

    public int addTreasure(String uid,String jobId){
        return userMapper.addTreasure(uid,jobId);

    }

    public int deleteTreasure(String uid,String jobId){

        return userMapper.deleteTreasure(uid,jobId);
    }

    public List<JobDetail> getMeetingJob(String uid){
        return userMapper.getMeetingJob(uid);

    }

    public int addMeeting(String uid,String jobId){
        return userMapper.addMeeting(uid,jobId);

    }


    public int deleteMeeting(String uid,String jobId){
        return userMapper.deleteMeeting(uid,jobId);
    }


    public List<JobDetail> getSendJob(String uid){
        return userMapper.getSendJob(uid);

    }

    public int addSend(String uid,String jobId){
        return userMapper.addSend(uid,jobId);

    }


    public int deleteSend(String uid,String jobId){
        return userMapper.deleteSend(uid,jobId);
    }

}
